package com.msw.system.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import java.sql.Timestamp;
import java.util.Set;

/**
 * @author mashuangwei
 * @date 2018-12-17
 */
@Getter
@Setter
@TableName("menu")
public class Menu {
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @NotBlank
    private String name;

    private Long sort;

    private String path;

    private String component;

    private String icon;

    private Long pid;

    /**
     * 是否为外链 true/false
     */
    @TableField("i_frame")
    private Boolean i_frame;

    @TableField(exist = false)
    private Set<Role> roles;

    @TableField("create_time")
    private Timestamp create_time;

    /**
     * 如果对象类型是 Menu 的话 则返回true 去比较hashCode值
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof Menu) {
            Menu menu = (Menu) obj;
            // 比较id和name一致时才返回true 之后再去比较 hashCode
            if (menu.id == this.id && menu.name.equals(this.name)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 重写hashcode 方法，返回的hashCode 不一样才认定为不同的对象
     */
    @Override
    public int hashCode() {
        return id.hashCode() * name.hashCode();
    }
}
